package com.zr.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.model.UserModel;
import com.zr.service.DatePswService;

public class DatePswController extends HttpServlet {
	
	DatePswService dps= new DatePswService();
	
      @Override
      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      	// TODO Auto-generated method stub
    	  doPost(req, resp);
      }
   
      @Override
      protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      	// TODO Auto-generated method stub
            String opsw =req.getParameter("opsw");
            String apsw =req.getParameter("apsw");
            HttpSession session =req.getSession();
            UserModel user =(UserModel)session.getAttribute("usermodel");
            int sid=user.getSid();
       
            UserModel  um=dps.validateUser(sid);
          String password= um.getSpwt();
          
          UserModel us= new UserModel();
          us.setSpwt(apsw);
          us.setSid(sid);
        
          
          if(opsw.equals(password)){
        	  dps.Datepsw(us);
        	  req.getRequestDispatcher("/funclist/DatepswSucessce.jsp").forward(req, resp);
          }
          else{
        	  req.getRequestDispatcher("/funclist/DatepswDeflat.jsp").forward(req, resp);
          }
         
      }
}
